package com.cz.video.web.controller.website;

import cn.xuyanwu.spring.file.storage.FileInfo;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.helper.LoginHelper;
import com.cz.video.common.storage.service.FileStorageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * {@code @Description} : oss控制器
 * {@code @Author} : 陈智
 * {@code @Date}: 21/11/2023  上午11:05
 */
@Tag(name = "oss管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/website/oss")
public class WebsiteOssController {
    private final FileStorageService fileStorageService;

    @PostMapping()
    @Operation(summary = "上传图片")
    public R<FileInfo> upload(@RequestParam("file") MultipartFile file) {

        FileInfo fileInfo = fileStorageService.upload(file, "user/" + LoginHelper.getUserId());
        return R.ok(fileInfo);
    }

}
